package BO;
import java.util.ArrayList;

import DB.CategoryDB;


public class Category implements Comparable<Category>{
	private int nr;
	private String name;
	private int parent;
	private ArrayList<Category> child;
	
	protected Category(int nr, String name, int parent){
		this.nr = nr;
		this.name = name;
		this.parent = parent;
		child = new ArrayList<Category>();
	}

	
	public int getNr() {
		return nr;
	}


	public void setNr(int nr) {
		this.nr = nr;
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public int getParent() {
		return parent;
	}


	public void setParent(int parent) {
		this.parent = parent;
	}

	public ArrayList<Category> getChild() {
		return child;
	}


	public void addChild(Category c) {
		child.add(c);
	}

	@Override
	public String toString() {
		String info = "Category [nr=" + nr + ", name=" + name + ", parent=" + parent;
		if(child != null){
			info += " " + child.toString();
		}
		info += "]";
		return info;
	}

	@Override
	public int compareTo(Category c) {
		if(parent == c.getParent())
			return 0;
		if(parent > c.getParent())
			return -1;
		return 1;
	}

	public static String getCategoryNameByNr(int nr){
		return CategoryDB.getCategoryNameByNr(nr);
	}
	
	public static void addCategory(String name, int parentId){
		CategoryDB.addCategory(name, parentId);
	}
	
	public static void editCategory(int categoryId, String name){
		CategoryDB.editCategory(categoryId, name);
	}
	
	public static boolean removeCategory(int id){
		return CategoryDB.removeCategory(id);
	}	
	
	public static ArrayList<Category> getCategoryTree(){
		return CategoryDB.getCategoryTree();
	}
	
	public static ArrayList<Category> getSubCategory(String name){
		return CategoryDB.getSubCategory(name);
	}

	
}
